/*
 * 文 件 名:  StreamDemo2.java
 * 描    述:  <描述>
 * 修 改 人:  yeyi
 * 修改时间:  2017年9月24日
 */
package test.stream;


import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class StreamDemo2 {

    public static void main(String[] args) {
        List<Student> lists = new ArrayList<Student>();
        lists.add(new Student(1,"张三","男"));
        lists.add(new Student(2,"李四","男"));
        lists.add(new Student(3,"赵六","女"));
        
        Stream<Student> stream = lists.stream();
        
        Stream<Student> boyStream=stream.filter((Student s)-> s.getSexy().equals("男"));
        System.out.println("男的人数:"+boyStream.count());
        //System.out.println("男的ID之和:"+boyStream.mapToInt( s->s.getId()).sum());
        
        IntStream  is = lists.stream().mapToInt( s->s.getId());
        System.out.println("ID编号之和为:"+is.sum());
        
        System.out.println(lists.stream().parallel().map(Student::getId).collect(Collectors.toList()));
    }

}

class Student{
    Integer id; 
    String name;
    String sexy;    
    
    public Student(Integer id, String name, String sexy) {
        super();
        this.id = id;
        this.name = name;
        this.sexy = sexy;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSexy() {
        return sexy;
    }
    public void setSexy(String sexy) {
        this.sexy = sexy;
    }
}
